package com.ruoyi.web.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.system.service.IPdfTokenService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping(value="/verify")
public class VerifyController {

    @Resource
    private IPdfTokenService pdfTokenService;

    @RequestMapping(value ="/sendMessageCode")
    @ResponseBody
    public String sendMessageCode(@RequestBody JSONObject data) {
        String signToken = "";
        String phoneNumber = "";
        if (data.containsKey("signToken")&&data.containsKey("phoneNumber")){
            signToken = data.getString("signToken");
            phoneNumber =data.getString("phoneNumber");
        }
        return pdfTokenService.sendMessageCode(signToken,phoneNumber);
    }

    @RequestMapping(value ="/verifyMessageCode")
    @ResponseBody
    public String verifyMessageCode(@RequestBody JSONObject data) {
        String signToken = "";
        String verifyCode = "";
        if (data.containsKey("signToken")&&data.containsKey("verifyCode")){
            signToken = data.getString("signToken");
            verifyCode =data.getString("verifyCode");
        }
        return pdfTokenService.verifyMessageCode(signToken,verifyCode);
    }

    @RequestMapping(value ="/verifyPassword")
    @ResponseBody
    public String verifyPassword(@RequestBody JSONObject data) {
        String signToken = "";
        String verifyCode = "";
        if (data.containsKey("signToken")&&data.containsKey("verifyCode")){
            signToken = data.getString("signToken");
            verifyCode =data.getString("verifyCode");
        }
        return pdfTokenService.verifyPassword(signToken,verifyCode);
    }
    @RequestMapping(value ="/queryVerifyType")
    @ResponseBody
    public String queryVerifyType(@RequestBody JSONObject data) {
        String signToken = "";
        JSONObject result = new JSONObject();
        if (data.containsKey("signToken")){
            signToken = data.getString("signToken");
        }
        result.put("code","0000");
        JSONArray jsonArray = new JSONArray();
        jsonArray.add("ESS_Verify_Password");
        jsonArray.add("ESS_Verify_Messages");
//        jsonArray.add("ESS_Verify_Face");
        result.put("msg",jsonArray);
        return result.toJSONString();
    }
}
